There are various types of recording media for recording digital data such as music content and video data, examples of which include a magnetic disk, an optical disc, and a magneto-optical disk. Among such recording media, memory cards that use a semiconductor memory such as a flash ROM as the recording element have rapidly become prevalent particularly in compact mobile devices such as digital still cameras and mobile phone terminals, due to the ability of the recording medium to be reduced in size. Moreover, in addition to applications as removable media as with conventional memory cards, semiconductor memory has recently been used in applications as internal device storage, such as incorporating a semiconductor memory such as a flash ROM into a device for use in place of a hard disk.
Mainly a semiconductor element called a NAND-type flash memory is used in such memory cards and internal device storage. A NAND-type flash memory is a recording element that, after previously recorded data has been erased once, can again record different data, and likewise to conventional hard disks, an information recording device in which rewriting can be performed multiple times can be configured by using a NAND-type flash memory.
Conventionally, data stored on a memory card or in internal device storage is managed using a file system. Managing data using a file system enables data to be shared as a file among devices that can interpret the same file system, and enables data stored by a user to be easily referenced from and copied among multiple devices by the user.
Conventionally, the most widely-used file system has been the so-called FAT file system. The FAT file system is widely used as the file system in floppy disks, PC hard disks, memory cards, and the like due to having the characteristic that area management is performed in a unified manner by a table called a file allocation table (FAT), as well as having a relatively simple structure and being easily implemented.
FIG. 2 shows a configuration of the FAT file system.
Although there are various types of FAT file systems, such as FAT12, FAT16, and FAT32, which differ in the bit width of the unit of management in the file allocation table, the method of area management using a file allocation table is substantially the same. The following describes FAT16 as an example.
As shown in FIG. 2, a file system management information area 301 is located at the head of a logical address space, and is an area in which file system management information is stored, which is information such as the unit in which area is allocated and the size of the area managed by the file system. This file system management information area 301 includes file system management information called a master boot record (MBR) partition table 303, a partition boot sector (PBS) 304, FATs (305 and 306), and a root directory entry (RDE) 307, each of which stores information necessary for managing a user data area 302. The master boot record partition table 303 is an area for storing information for managing the area in the logical address space managed by the file system, by dividing the area into a plurality of areas called partitions. The partition boot sector 304 is an area for storing information regarding management in a partition, such as the size of the unit of area management in the partition. The FATs (305 and 306) are areas for storing information related to the storage locations of data contained in files, and normally there are two FATs (305 and 306) that hold the same information, thus providing duplication such that even if one of the FATs (305 or 306) is damaged, files can be accessed using the other FAT (305 or 306). The root directory entry 307 is an area for storing information (directory entries) regarding files and directories that exist directly under the root directory.
Also, in the FAT file system, the user data area 302 for storing the data of actual files and the like follows the file system management information area 301. The user data area 302 is divided into and managed in management units called clusters that have a size of approximately 512 bytes to 32 KB, and data included in files is stored in the clusters. When a file stores a large amount of data, the data is stored spanning multiple clusters, and the connection between the clusters is managed by link information stored in the FATs (305 and 306). Also, information (directory entries) related to the files and subdirectories located in a directory immediately under the root directory is stored using a portion of the user data area 302.
FIG. 3 is a diagram showing a configuration of a FAT16 directory entry.
One 32-byte directory entry 308 is allocated for each file and directory, and stores information related to the file or directory. Specifically, each time a file or directory is added, information for a new 32-byte directory entry 308 is created and recorded in an area of the root directory entry 307 or in the user data area 302. The name of the file or directory is stored in the first eight bytes of the directory entry 308. The extension is stored in the next three bytes. The next one byte stores attribute information such as a flag identifying the type of file or directory, and a flag identifying whether the file or directory is read-only. The directory entry 308 also stores, for example, information indicating the last-updated date/time of the file or directory, a starting cluster number indicating the start location of the clusters storing the actual file or directory, and the file size in number of bytes. Such a directory entry 308 only holds information related to the location of the cluster holding data at the head of the file, and therefore in the case where file data is stored spanning multiple clusters, the location information of the clusters is held in the FATs (305 and 306). In other words, in the case of updating a file, in addition to writing the file data, it is necessary to write information in the directory entry 308 and the FATs (305 and 306) as well.
<<File Data Writing Processing FAT File System>>
Next is a description of a procedure of file data writing processing in the FAT file system with reference to FIG. 4.
(S401):
In S401, the directory entry 308 of the target file is read out.
(S402):
In S402, the starting cluster number stored in the directory entry 308 that was read out is acquired, and the head location of the file data is checked.
(S403):
In S403, the FAT (305 or 306) is read out to a RAM of an access module, and the cluster number of the writing location is acquired by following the links in the FAT (305 or 306) in the RAM from the head location of the file data acquired in S402.
(S404):
In S404, a determination is made as to whether a new free area needs to be allocated to the file when writing file data. If the result of the determination is that a free area needs to be allocated, the procedure moves to the processing of S405. On the other hand, if a free area does not need to be allocated, the procedure moves to the processing of S408.
(S405):
In S405, one cluster-worth of free area is acquired by searching for a free area in the FAT (305 or 306) in the RAM. Since a value of 0x0000 set in a FAT entry in the FATs (305 and 306) represents that the FAT entry is a free cluster, the processing for acquiring a free area is processing for acquiring a FAT entry having the value 0x0000 in the FAT (305 or 306). Specifically, the FAT entries in the FAT (305 or 306) in the RAM are sequentially referenced, a FAT entry in which the value 0x0000 is set is found, and the value of the cluster number corresponding to that FAT entry is obtained. The processing for searching for a FAT entry may be implemented by, for example, searching for a FAT entry in order from the head of the FAT (305 or 306) to the end thereof. Alternatively, the processing for searching for a FAT entry may be executed by starting the search processing at the FAT entry following the FAT entry to which a free area was previously allocated, and if the end of the FAT (305 or 306) is reached, returning to the head of the FAT (305 or 306) and continuing the search up to the FAT entry to which a free area was previously allocated. In this way, there is no limitation on the procedure of FAT entry search processing, as long as it is possible to realize processing for searching the entirety of the FAT (305 or 306) area for a free area.
(S406):
In S406, the value of the FAT entry corresponding to the free cluster number acquired in S405 is set to a value indicating the link tail. Since a value of 0xFFFF set in a FAT entry in the FAT (305 or 306) represents that the FAT entry is the link tail, processing for setting the value of the corresponding FAT entry to 0xFFFF in the RAM is implemented in S406.
(S407):
In S407, the value of the FAT entry corresponding to the cluster number of the current link tail is changed in the RAM from 0xFFFF to the number of the free cluster acquired in S405. If a free area needs to be acquired (the determination result of S404 is “Yes”), an addition is made to the end of the file. In other words, in this case, the links have been followed to the end of the file in the processing for following links in S403, and therefore the value of the FAT entry corresponding to the cluster number of the current link tail has been set to 0xFFFF, which represents the link tail. For this reason, in the processing of S407, a link is connected to the new free cluster that was acquired in S405, and therefore the file links become one cluster-worth longer, and file data can be added.
(S408):
In S408, file data is written to the cluster at the currently referenced writing location. If it was determined in S404 that a free area needs to be acquired, the currently referenced writing location is the free cluster acquired in S405. On the other hand, if it was determined in S404 that a free area does not need to be acquired, the currently referenced writing location is the cluster arrived at as a result of following the links in S403.
(S409):
In S409, a determination is made as to whether the writing of all of the file data has been completed. If any file data remains, the procedure returns to the processing of S404. If the writing of all of the file data has been completed, the procedure proceeds to the processing of S410.
(S410):
Information such as the file size and last updated date/time stored in the directory entry 308 are updated, and the directory entry 308 stored in a non-volatile memory of an information recording module is overwritten.
(S411):
In S411, the FATs (305 and 306) stored in the non-volatile memory of the information recording module are overwritten with the data of the FAT (305 or 306) in the RAM of the access module, thereby completing the processing.
According to the file data writing processing described above, in the case of adding 10,000 bytes of data to FILE1.TXT, which is shown in FIG. 5 and has 60,000 bytes of data, this file (FILE1.TXT) changes to a file having 70,000 bytes of data as shown in FIG. 6. Specifically, the cluster with the cluster number 6 is acquired as a free cluster, file data is added to the acquired cluster, and a link connecting to the cluster number 6 is written to the FAT (305 or 306). As a result, the links of the file FILE1.TXT are updated from being made up of the four clusters with the cluster numbers 2 to 5, to being made up of the five clusters with the cluster numbers 2 to 6. In this way, in the FAT file system, since file management information is stored in both the FATs (305 and 306) and the directory entry 308, such information (information in the FATs (305 and 306) and information in the directory entry 308) also needs to be updated when updating a file.
Incidentally, NAND-type flash memory has the characteristic that data needs to be erased once before data is recorded. In the case of writing data whose size is less than the size of a block, which is the unit of data erasure, to a NAND-type flash memory, the corresponding block cannot be directly overwritten, and therefore it is necessary to acquire a different unused block, erase the data in the acquired block, and write the new data to the block whose data was erased. At this time, the valid data contained in the old block needs to copied to the new block, thus reducing the speed at which data is recorded. The amount of copying performed when recording this data increases the smaller the size of the data to be written is, and decreases the closer the size of the data to be written is to the block size. For this reason, it is known that the data recording speed is generally faster when data is written to a NAND-type flash memory in units of the block size.
Conventionally, a method has been proposed that realizes real-time recording (data writing processing in which a certain writing speed is guaranteed) of video content and the like by increasing the speed of recording to a NAND-type flash memory and preventing a decrease in the data recording speed due to the above-described copy processing (e.g., see Patent Literature 1). With this method (the method disclosed in Patent Literature 1), if the area in the flash memory is divided into block units, only a block that contains a large number of free areas (free clusters) is acquired, and data such as video content is recorded to the acquired block. Doing this reduces the amount of data copying in a block, thus preventing a decrease in the recording speed.
Also, in the case where the access module updates a file stored in the information recording module, with the FAT file system, it is necessary to update file system management information in the FATs (305 and 306), the directory entry 308, and the like, in addition to recording the actual data, as described with reference to FIG. 4. Conventionally, a method has been proposed that increases the speed of updating such file system management information in a NAND-type flash memory (e.g., see Patent Literature 2). With this method (the method disclosed in Patent Literature 2), in the case of recording user data and file system management information, the access device notifies the recording medium of the data type, thus enabling the recording medium to implement storage methods that are in accordance with the characteristics of the respective data, and perform high-speed recording even when recording a combination of high-volume data such as user data and low-volume data such as file system management information.